﻿@inject IStringLocalizer<ValidateForms> Localizer

<ValidateForm Model="@Model" @ref="ValidatorForm">
    <div class="row g-3">
        <div class="col-12 col-sm-6">
            <BootstrapInput @bind-Value="@Model.Name" />
        </div>
        <div class="col-12 col-sm-6">
            <BootstrapInput @bind-Value="@Model.Address" />
        </div>
    </div>
</ValidateForm>
<Button Icon="fa-solid fa-floppy-disk" Text="@Localizer["ValidateButtonText"]" OnClickWithoutRender="OnValidator" class="my-3"></Button>

@code {
    [NotNull]
    private Foo? Model { get; set; }

    /// <summary>
    /// OnInitializedAsync 方法
    /// </summary>
    /// <returns></returns>
    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();

        // 切换线程 模拟异步通过 webapi 加载数据
        await Task.Yield();

        Model = new() { Name = "Name", Education = EnumEducation.Primary, DateTime = DateTime.Now };
    }

    [NotNull]
    private ValidateForm? ValidatorForm { get; set; }

    private Task OnValidator()
    {
        ValidatorForm.Validate();
        return Task.CompletedTask;
    }
}
